package ferp.android.dialogs;

import android.content.Context;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
import ferp.android.GUI;
import ferp.android.R;

/**
* User: igorgok
* Date: 5/29/12 2:21 PM
*/
public class ProgressDialog extends Dialog
{
  public ProgressDialog(Context context)
  {
    this(context, null);
  }

  public ProgressDialog(Context context, OnCancelListener listener)
  {
    super(context, R.layout.dialog_progress);

    this.listener = listener;
    setOnCancelListener(listener);

    setCancelable(listener != null);

    message = (TextView)findViewById(R.id.dlg_progress_text);
    message.setTypeface(GUI.Font.BOLD);

    image = (ImageView)findViewById(R.id.dlg_progress_image);
    animation = AnimationUtils.loadAnimation(context, R.anim.sand_clock_rotate);
  }

  public ProgressDialog set(int title, int message) {return set(title, getContext().getString(message));}

  public ProgressDialog set(int title, String message)
  {
    this.title.setText(title);
    this.message.setText(message);

    image.startAnimation(animation);

    return this;
  }

  @Override
  public void dismiss()
  {
    animation.cancel();

    super.dismiss();
  }

  // listener
  private OnCancelListener listener;

  // widgets
  private final TextView message;
  private final ImageView image;
  private final Animation animation;
}
